package org.extframework.ld.util;
import java.util.Random;
 
/**
 * @author dong.li
 * @date 2014-3-15下午03:09:23
 * @Description: 编码工具
 * @version V1.0
 */
public class CodeUtil {
     
    private CodeUtil() {}
     
    private static final Random RAN_DOM = new Random();
     
    private static final int MAX = 'Z'-'A'+1;
    private static final int CHA = 'a'-'A';//得到 小写与大写之间的差
     
     
    private static final char GET_CHAR(){
        char c = (char) (RAN_DOM.nextInt(MAX)+'A');//随机产生A-Z char
        c = RAN_DOM.nextBoolean()?(char)(c+CHA):c;//随机大小写
        return c;
    }
     
    /**
     * 生成随机数
     * @param len
     * @return
     */
    public static final String GET_CODE( int len ){
        StringBuffer sb = new StringBuffer();
        for(int i=0;i<len;i++){
            sb.append(GET_CHAR());
        }
        return sb.toString();
    }
     
}